﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/Admin.master" AutoEventWireup="true"
    CodeBehind="ServiceReport.aspx.cs" Inherits="SEP.Admin.ServiceReportPage" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajt" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cphHead" runat="server">
    <script src="../Scripts/jquery-ui.min.js" type="text/javascript"></script>
    <link href="../Styles/jquery-ui.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $(document).ready(function () {
            DefineInputMasks();
            //when update panel contents are refreshed, document.ready() is *not* called again
            //so we register an endrequest handler which will re-register our behavior
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(UpdatePanelRequestHandler);
        });

        function UpdatePanelRequestHandler() {
            DefineInputMasks();
        }
        
        function DefineInputMasks() {            
            $(".datepicker").datepicker({
                changeMonth: true,
                changeYear: true
            });
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphTitle" runat="server">
    Service Report Creation
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="cphBody" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <asp:UpdatePanel ID="udpGrvInstrumentSearch" runat="server">
        <ContentTemplate>
            <table border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td class="alignLeft">
                        <h3>
                            Instrument</h3>
                    </td>
                    <td class="alignRight">
                        <asp:Button ID="btnInstrumentSearch" runat="server" Text="Search" OnClick="btnInstrumentSearch_Click" CausesValidation="false" />
                    </td>
                </tr>
                <tr>
                    <td class="alignLeft" colspan="2">
                        <table border="1" rules="all" cellpadding="10" cellspacing="10">
                            <tr>
                                <td>
                                    Instrument type
                                </td>
                                <td>
                                    <asp:TextBox ID="txtInstrumentType" runat="server" MaxLength="100" TabIndex="21" />
                                </td>
                                <td>
                                    Unit no
                                </td>
                                <td>
                                    <asp:TextBox ID="txtUnitNumber" runat="server" MaxLength="100" TabIndex="24" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Manufacturer
                                </td>
                                <td>
                                    <asp:TextBox ID="txtManufacturer" runat="server" MaxLength="100" TabIndex="22" />
                                </td>
                                <td>
                                    Serial no
                                </td>
                                <td>
                                    <asp:TextBox ID="txtSerialNumber" runat="server" MaxLength="100" TabIndex="25" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Model <asp:RequiredFieldValidator ID="rfvTxtModel" runat="server" Text="* Required" ErrorMessage="Instrument model required" ControlToValidate="txtModel" ForeColor="Red" SetFocusOnError="true" />
                                </td>
                                <td>
                                    <asp:TextBox ID="txtModel" runat="server" MaxLength="100" TabIndex="23" />
                                </td>
                                <td>
                                    PO #
                                </td>
                                <td>
                                    <asp:TextBox ID="txtPONumber" runat="server" MaxLength="50" TabIndex="26" />
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
            <%--start instrument modal--%>
            <ajt:ModalPopupExtender ID="modalInstrumentSearch" runat="server" CancelControlID="btnInstrumentCancel"
                TargetControlID="btnInstrumentSearch" PopupControlID="pnlInstrumentSearch" PopupDragHandleControlID="PopupHeader"
                Drag="true" BehaviorID="ShowInstrumentModal" BackgroundCssClass="modalBackground">
            </ajt:ModalPopupExtender>
            <asp:Panel ID="pnlInstrumentSearch" runat="server">
                <div id="modalInstrument">
                    <div class="modal">
                        <table width="400" border="0">
                            <tr>
                                <td colspan="2" align="right">
                                    <asp:TextBox ID="txtInstrumentSearch" runat="server" />
                                    <asp:Button ID="btnInstrumentSubmit" runat="server" Text="Search" CausesValidation="false"
                                        OnClick="btnInstrumentSubmit_Click" OnClientClick="showInstrumentModal();" />
                                </td>
                            </tr>
                            <tr>
                                <td align="center" colspan="2">
                                    <asp:GridView ID="grvInstrumentSearch" runat="server" AutoGenerateColumns="false"
                                        PagerSettings-NextPageText="Next" PagerSettings-PreviousPageText="Previous" PagerSettings-Mode="NextPrevious"
                                        PageSize="5" AllowPaging="true" OnPageIndexChanging="grvInstrumentSearch_PageIndexChanging"
                                        AllowSorting="true" OnSorting="grvInstrumentSearch_OnSorting" OnSelectedIndexChanging="grvInstrumentSearch_OnSelectedIndexChanging">
                                        <Columns>
                                            <asp:CommandField SelectText="Select" ButtonType="Link" ShowSelectButton="true" />
                                            <asp:BoundField DataField="INSTRUMENTTYPE" HeaderText="Instrument type" SortExpression="INSTRUMENTTYPE" />
                                            <asp:BoundField DataField="MANUFACTURER" HeaderText="Manufacturer" SortExpression="MANUFACTURER" />
                                            <asp:BoundField DataField="MODEL" HeaderText="Model" SortExpression="MODEL" />
                                            <asp:BoundField DataField="ID" Visible="false" />
                                        </Columns>
                                    </asp:GridView>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <br />
                                </td>
                            </tr>
                            <tr>
                                <td align="left" colspan="2">
                                    <asp:Button ID="btnInstrumentCancel" runat="server" Text="Cancel" CausesValidation="false" />
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </asp:Panel>
            <%--end instrument modal--%>
        </ContentTemplate>
    </asp:UpdatePanel>
    <hr />
    <table>
        <tr>
            <td class="alignLeft">
                <h3>
                    Service required</h3>
            </td>
        </tr>
        <tr>
            <td class="alignLeft">
                <asp:TextBox ID="txtServiceRequired" runat="server" TextMode="MultiLine" MaxLength="4000"
                    Rows="7" Columns="60" TabIndex="27" />
            </td>
        </tr>
        <tr>
            <td class="alignLeft">
                <h3>
                    Service performed</h3>
            </td>
        </tr>
        <tr>
            <td>
                <asp:TextBox ID="txtServicePerformed" runat="server" TextMode="MultiLine" MaxLength="4000"
                    Rows="7" Columns="60" TabIndex="28" />
            </td>
        </tr>
    </table>
    <hr />
    <asp:UpdatePanel ID="updGrvPartSearch" runat="server">
        <ContentTemplate>
            <table border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td class="alignLeft">
                        <h3>
                            Parts</h3>
                    </td>
                    <td class="alignRight">
                        <asp:Button ID="btnPartSearch" runat="server" Text="Search" OnClick="btnPartSearch_Click" CausesValidation="false" />
                    </td>
                </tr>
                <tr>
                    <td class="alignLeft" colspan="2">
                        <table border="1" rules="all" cellpadding="10" cellspacing="10">
                            <tr>
                                <td>
                                    Description
                                </td>
                                <td>
                                    <asp:TextBox ID="txtPartDescription" runat="server" MaxLength="100" TabIndex="29" />
                                </td>
                                <td>
                                    Part number
                                </td>
                                <td>
                                    <asp:TextBox ID="txtPartNumber" runat="server" MaxLength="100" TabIndex="30" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Price
                                </td>
                                <td>
                                    <asp:TextBox ID="txtPartPrice" runat="server" MaxLength="100" TabIndex="31" />
                                </td>
                                <td>
                                    Quantity
                                </td>
                                <td>
                                    <asp:TextBox ID="txtPartQuantity" runat="server" MaxLength="2" TabIndex="32" />
                                    <asp:HiddenField ID="hfPartID" runat="server" />
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4" class="alignRight">
                                    <asp:Button ID="btnPartAdd" runat="server" Text="Add" OnClick="btnPartAdd_Click" TabIndex="33" CausesValidation="false" />
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <br />
                    </td>
                </tr>
                <tr>
                    <td colspan="2" class="alignLeft" align="left">
                        <asp:GridView ID="grvParts" runat="server" AutoGenerateColumns="false" ShowHeaderWhenEmpty="false" DataKeyNames="ID"
                            HorizontalAlign="Left" OnRowDeleting="grvParts_DeleteRecord" OnRowDataBound="grvParts_RowDataBound">
                            <Columns>
                                <asp:TemplateField HeaderText="Description">
                                    <ItemTemplate>
                                        <asp:Literal ID="litPartDescription" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Description") %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Part number">
                                    <ItemTemplate>
                                        <asp:Literal ID="litPartNumber" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Number") %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Quantity">
                                    <ItemTemplate>
                                        <asp:Literal ID="litPartQuantity" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Quantity") %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Price">
                                    <ItemTemplate>
                                        <asp:Literal ID="litPartPrice" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Price", "{0:C}") %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Total">
                                    <ItemTemplate>
                                        <asp:Literal ID="litPartTotal" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Total", "{0:C}") %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField Visible="false">
                                    <ItemTemplate>
                                        <asp:Literal ID="litPartID" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ID") %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField ItemStyle-Width="50px" ItemStyle-HorizontalAlign="Center">
                                    <ItemTemplate>
                                        <asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%# Eval("ID") %>'
                                            CommandName="Delete" Text="Delete" ForeColor="Black" CausesValidation="false" />
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>
                    </td>
                </tr>
            </table>
            <%--start part modal--%>
            <ajt:ModalPopupExtender ID="modalPartSearch" runat="server" CancelControlID="btnPartCancel"
                TargetControlID="btnPartSearch" PopupControlID="pnlPartSearch" PopupDragHandleControlID="PopupHeader"
                Drag="true" BehaviorID="ShowPartModal" BackgroundCssClass="modalBackground">
            </ajt:ModalPopupExtender>
            <asp:Panel ID="pnlPartSearch" runat="server">
                <div id="modalPart">
                    <div class="modal">
                        <table width="400" border="0">
                            <tr>
                                <td colspan="2" align="right">
                                    <asp:TextBox ID="txtPartSearch" runat="server" />
                                    <asp:Button ID="btnPartSubmit" runat="server" Text="Search" CausesValidation="false"
                                        OnClick="btnPartSubmit_Click" OnClientClick="showPartModal();" />
                                </td>
                            </tr>
                            <tr>
                                <td align="center" colspan="2">
                                    <asp:GridView ID="grvPartSearch" runat="server" AutoGenerateColumns="false" PagerSettings-NextPageText="Next"
                                        PagerSettings-PreviousPageText="Previous" PagerSettings-Mode="NextPrevious" PageSize="5"
                                        AllowPaging="true" OnPageIndexChanging="grvPartSearch_PageIndexChanging" AllowSorting="true"
                                        OnSorting="grvPartSearch_OnSorting" OnSelectedIndexChanging="grvPartSearch_OnSelectedIndexChanging">
                                        <Columns>
                                            <asp:CommandField SelectText="Select" ButtonType="Link" ShowSelectButton="true" />
                                            <asp:BoundField DataField="DESCRIPTION" HeaderText="Description" SortExpression="DESCRIPTION" />
                                            <asp:BoundField DataField="PARTNUMBER" HeaderText="Part number" SortExpression="PARTNUMBER" />
                                            <asp:BoundField DataField="PRICE" HeaderText="Price" SortExpression="PRICE" DataFormatString="{0:C}" />
                                            <asp:TemplateField Visible="false">
                                                <ItemTemplate>
                                                    <asp:HiddenField ID="hfPartSearchID" runat="server" Value='<%#DataBinder.Eval(Container.DataItem, "ID") %>' />
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                        </Columns>
                                    </asp:GridView>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <br />
                                </td>
                            </tr>
                            <tr>
                                <td align="left" colspan="2">
                                    <asp:Button ID="btnPartCancel" runat="server" Text="Cancel" CausesValidation="false" />
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </asp:Panel>
            <%--end part modal--%>
        </ContentTemplate>
    </asp:UpdatePanel>
    <hr />
    <asp:UpdatePanel ID="udpTotals" runat="server" OnLoad="udpTotals_Load">
        <ContentTemplate>
            <table>
                <tr>
                    <td>
                        <table border="1" rules="all" cellpadding="10" cellspacing="10">
                            <tr>
                                <td width="90px">
                                    Date
                                </td>
                                <td width="70px">
                                    Labor
                                </td>
                                <td width="70px">
                                    Travel
                                </td>
                                <td width="70px">
                                    Mileage
                                </td>
                                <td width="70px">
                                    Other
                                </td>
                                <td width="200px">
                                    Other Description
                                </td>
                                <td width="50px">
                                </td>
                            </tr>
                            <tr>
                                <td valign="top">
                                    <asp:TextBox ID="txtDate" runat="server" Width="70px" CssClass="datepicker" TabIndex="34" />
                                    <asp:RequiredFieldValidator ID="rfvTxtDate" runat="server" ControlToValidate="txtDate"
                                        Text="*" Display="Static" ForeColor="Red" ValidationGroup="ServiceTotalsValidationGroup" />
                                </td>
                                <td valign="top">
                                    <asp:TextBox ID="txtLabor" runat="server" Width="50px" TabIndex="35" />
                                    <asp:RangeValidator ID="RangeValidator1" runat="server" Type="Double" ControlToValidate="txtLabor" ErrorMessage="Number only" ForeColor="Red" />
                                </td>
                                <td valign="top">
                                    <asp:TextBox ID="txtTravel" runat="server" Width="50px" TabIndex="36" />
                                    <asp:RangeValidator ID="RangeValidator4" runat="server" Type="Double" ControlToValidate="txtTravel" ErrorMessage="Number only" ForeColor="Red" />
                                </td>
                                <td valign="top">
                                    <asp:TextBox ID="txtMileage" runat="server" Width="50px" TabIndex="37" />
                                    <asp:RangeValidator ID="RangeValidator3" runat="server" Type="Double" ControlToValidate="txtMileage" ErrorMessage="Number only" ForeColor="Red" />
                                </td>
                                <td valign="top">
                                    <asp:TextBox ID="txtOther" runat="server" Width="50px" TabIndex="38" />
                                    <asp:RangeValidator ID="RangeValidator2" runat="server" Type="Double" ControlToValidate="txtOther" ErrorMessage="Number only" ForeColor="Red" />
                                </td>
                                <td valign="top">
                                    <asp:TextBox ID="txtOtherDescription" runat="server" Width="150px" TabIndex="39" TextMode="MultiLine" />
                                </td>
                                <td valign="top">
                                    <asp:Button ID="btnAddTotals" runat="server" Text="Add" OnClick="btnAddTotals_Click"
                                        ValidationGroup="ServiceTotalsValidationGroup" TabIndex="40" CausesValidation="false" />
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td>
                        <br />
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <asp:GridView ID="grvTotals" runat="server" AutoGenerateColumns="false" HorizontalAlign="Left"
                            DataKeyNames="ID" OnRowDataBound="grvTotals_RowDataBound" OnRowDeleting="grvTotals_DeleteRecord">
                            <Columns>
                                <asp:TemplateField HeaderText="Date" ItemStyle-Width="90px" ItemStyle-HorizontalAlign="Center">
                                    <ItemTemplate>
                                        <asp:Literal ID="litDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Date", "{0:MM/dd/yyyy}") %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Labor" ItemStyle-Width="70px" ItemStyle-HorizontalAlign="Center">
                                    <ItemTemplate>
                                        <asp:Literal ID="litLabor" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Labor") %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Travel" ItemStyle-Width="70px" ItemStyle-HorizontalAlign="Center">
                                    <ItemTemplate>
                                        <asp:Literal ID="litTravel" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Travel") %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Mileage" ItemStyle-Width="70px" ItemStyle-HorizontalAlign="Center">
                                    <ItemTemplate>
                                        <asp:Literal ID="litMileage" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Mileage") %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Other" ItemStyle-Width="70px" ItemStyle-HorizontalAlign="Center">
                                    <ItemTemplate>
                                        <asp:Literal ID="litOther" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Other") %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Other Description" ItemStyle-Width="150px" ItemStyle-HorizontalAlign="Center">
                                    <ItemTemplate>
                                        <asp:Literal ID="litOtherDescription" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "OtherDescription") %>' />
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField ItemStyle-Width="50px" ItemStyle-HorizontalAlign="Center">
                                    <ItemTemplate>
                                        <asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%# Eval("ID") %>'
                                            CommandName="Delete" Text="Delete" ForeColor="Black" CausesValidation="false" />
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>
                    </td>
                </tr>
                <tr>
                    <td>
                        <br />
                    </td>
                </tr>
                <tr>
                    <td>
                        <table border="1" rules="all" cellpadding="10" cellspacing="10">
                            <tr>
                                <td class="center" width="70px">
                                    Total parts
                                </td>
                                <td class="center" width="70px">
                                    Total labor
                                </td>
                                <td class="center" width="70px">
                                    Total travel
                                </td>
                                <td class="center" width="90px">
                                    Total mileage
                                </td>
                                <td class="center" width="70px">
                                    Total other
                                </td>
                                <td class="center" width="140px">
                                    Other descriptions
                                </td>
                            </tr>
                            <tr>
                                <td class="center">
                                    <asp:Literal ID="litTotalParts" runat="server" />
                                </td>
                                <td class="center">
                                    <asp:Literal ID="litTotalLabor" runat="server" />
                                </td>
                                <td class="center">
                                    <asp:Literal ID="litTotalTravel" runat="server" />
                                </td>
                                <td class="center">
                                    <asp:Literal ID="litTotalMileage" runat="server" />
                                </td>
                                <td class="center">
                                    <asp:Literal ID="litTotalOther" runat="server" />
                                </td>                                
                                <td class="center">
                                    <asp:Literal ID="litOtherDescriptions" runat="server" />
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </ContentTemplate>
    </asp:UpdatePanel>
    <br />
    <br />
    <asp:Button ID="btnSave" runat="server" Text="Save Service Report" OnClick="btnSave_OnClick" TabIndex="41"
        Visible="true" />
        <asp:ValidationSummary ID="validationSummary1" runat="server" ShowMessageBox="true" ShowSummary="false" />
    <br />
    <hr />
    <br />
    <asp:Button ID="btnSendToIan" runat="server" Text="Send to Ian" TabIndex="42" 
        onclick="btnSendToIan_Click" />
    <asp:Button ID="btnSendToJenny" runat="server" Text="Send to Jenny" TabIndex="43" 
        onclick="btnSendToJenny_Click" />
</asp:Content>
